using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using PlugNT.Safe;
using PlugNT.Cms.Custom;
using PlugNT.Database;
using PlugNT.Database.Common.Simple;
using PlugNT.App.Payment.Model;

namespace PlugNT.App.Payment.BLL
{
    public class Incharge
    {

        private static readonly PlugNT.App.Payment.DAL.Incharge dal = new PlugNT.App.Payment.DAL.Incharge();



        public static string GetTableName()
        {
            return PlugNT.App.Payment.DAL.Incharge.currTableName;
        }

        public static string GetAddSql(InchargeInfo model)
        {
            return PlugNT.App.Payment.DAL.Incharge.GetAddSql(model);
        }

        public static InchargeInfo GetInchargeInfo(int id)
        {
            return PlugNT.App.Payment.DAL.Incharge.GetInchargeInfo(id);
        }


        public static InchargeInfo GetInchargeInfo(string no)
        {
            return PlugNT.App.Payment.DAL.Incharge.GetInchargeInfo(no);
        }



        public bool Add(InchargeInfo model)
        {
            return dal.Add(model);
        }





        public bool Delete(int id)
        {
            return dal.Delete(id, " and [state]=0 ");
        }













        public DataTable GetList(int sysModelId, int pageSize, int currPage, int userId, int state, out int recordCount)
        {
            LeftJoinInfo joininfo = new LeftJoinInfo(WebConfig.UsersTableName, "username", "user_id", WebConfig.GetUserField("id"), "");
            StringBuilder andWhere = new StringBuilder();
            if (userId > 0)
            {
                andWhere.Append(" and [user_id]=" + userId.ToString());
            }
            if (state > 0)
            {
                andWhere.Append(" and [state]=" + state.ToString());
            }
            recordCount = dal.GetCount(sysModelId, andWhere.ToString());
            return dal.GetList(sysModelId, pageSize, currPage,  andWhere.ToString() ,joininfo);
        }


 

    }
}

